package com.hy.mydesktop.client.component.mvc.factory.util;

import java.util.List;
import java.util.Set;

import com.hy.mydesktop.client.component.event.AppEvents;
import com.hy.mydesktop.client.mvc.base.BaseController;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentControllerMetaNodeModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.MetaDataConstants;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtAppEventType;


public class ControllerFactoryUtilTemplate {
	
	public static void addRegisterEventTypeToContorller(BaseController baseController,GxtComponentControllerMetaNodeModel gxtComponentControllerMetaNodeModel) {
		
		//注册BaseController(例如：WindowController)，需要监听的事件
		//if(gxtComponentControllerMetaNodeModel.get(WindowControllerModelEnum.REGISTEREVENTTYPES.name().toLowerCase())!=null){
//		if(gxtComponentControllerMetaNodeModel.get(MetaDataConstants.REGISTER_EVENT_TYPES)!=null||gxtComponentControllerMetaNodeModel.get(MetaDataConstants.APP_EVENT_TYPES)!=null){
		if(gxtComponentControllerMetaNodeModel.get(MetaDataConstants.REGISTER_EVENT_TYPES)!=null||gxtComponentControllerMetaNodeModel.get(MetaDataConstants.APP_EVENT_TYPES)!=null){
			
			Set<GxtAppEventType> appEventCodes = null;
			if (gxtComponentControllerMetaNodeModel.get(MetaDataConstants.REGISTER_EVENT_TYPES)!=null) {				
				appEventCodes =	gxtComponentControllerMetaNodeModel.get(MetaDataConstants.REGISTER_EVENT_TYPES);
							
			} else {
				appEventCodes =	gxtComponentControllerMetaNodeModel.get(MetaDataConstants.APP_EVENT_TYPES);

			}
			for (GxtAppEventType code : appEventCodes) {
				
				Integer i = Integer.valueOf(code.getRegisterEventType());
				switch (i) {
		            case 1://Integer.valueOf("0001")
		            	baseController.addRegisterEventType(AppEvents.DESKTOP_USER_LOGIN);
		            	
		                break;
		            case 2://Integer.valueOf("0002")
		            	baseController.addRegisterEventType(AppEvents.DESKTOP_INIT_FOR_LOGGED_IN_USER);	
		                break;
		                
		            case 3://Integer.valueOf("0003")
		            	baseController.addRegisterEventType(AppEvents.DESKTOP_SHORTCUT_ONCLICK_INIT);	
		                break;
		            case 5://Integer.valueOf("0006")
		            	baseController.addRegisterEventType(AppEvents.DESKTOP_MENUITEM_ONCLICK_INIT);	
		                break;
		            case 6://Integer.valueOf("0006")
		            	baseController.addRegisterEventType(AppEvents.DESKTOP_WINDOW_INIT);	
		                break;
		            case 7://Integer.valueOf("0007")
		            	baseController.addRegisterEventType(AppEvents.DESKTOP_WINDOWAPPLICATION_INIT);	
		                break;
		            case 8://Integer.valueOf("0008")
		            	baseController.addRegisterEventType(AppEvents.DESKTOP_APPLICATION_RENDER);	
		                break;
		            case 10://Integer.valueOf("0008")
		            	baseController.addRegisterEventType(AppEvents.DESKTOP_SUB_APPLICATION_INIT);	
		                break;
		                
		            case 101://Integer.valueOf("0101")
		            	baseController.addRegisterEventType(AppEvents.WINDOW_ININT);
		                break;
		            case 201://Integer.valueOf("0201")
		            	baseController.addRegisterEventType(AppEvents.CONTENTPANEL_ININT);
		                break;
		            case 301://Integer.valueOf("0301")
		            	baseController.addRegisterEventType(AppEvents.FORM_TEXTFIELD_ONCLICK);
		                break;
		            case 401://Integer.valueOf("0401")
		            	baseController.addRegisterEventType(AppEvents.LOAD_DATA_EVENT);
		                break;
		            case 601://Integer.valueOf("0401")
		            	baseController.addRegisterEventType(AppEvents.GRID_RELOAD);
		                break;
		            case 602://Integer.valueOf("0401")
		            	baseController.addRegisterEventType(AppEvents.GRID_RELOAD_COLUMN);
		                break;
		            case 603://Integer.valueOf("0401")
		            	baseController.addRegisterEventType(AppEvents.GRID_RELOAD_STORE);
		                break;
		            default:
		                break;
		        }
			}
			/**
			 List<String>   appEventCodes2 =	gxtComponentControllerMetaNodeModel.get(MetaDataConstants.APP_EVENT_TYPES);
				
				for (String code : appEventCodes2) {
					
					Integer i = Integer.valueOf(code);
					switch (i) {
			            case 1://Integer.valueOf("0001")
			            	baseController.addRegisterEventType(AppEvents.DESKTOP_USER_LOGIN);
			            	
			                break;
			            case 2://Integer.valueOf("0002")
			            	baseController.addRegisterEventType(AppEvents.DESKTOP_INIT_FOR_LOGGED_IN_USER);	
			                break;
			                
			            case 3://Integer.valueOf("0003")
			            	baseController.addRegisterEventType(AppEvents.DESKTOP_SHORTCUT_ONCLICK_INIT);	
			                break;
			            case 5://Integer.valueOf("0006")
			            	baseController.addRegisterEventType(AppEvents.DESKTOP_MENUITEM_ONCLICK_INIT);	
			                break;
			            case 6://Integer.valueOf("0006")
			            	baseController.addRegisterEventType(AppEvents.DESKTOP_WINDOW_INIT);	
			                break;
			            case 7://Integer.valueOf("0007")
			            	baseController.addRegisterEventType(AppEvents.DESKTOP_APPLICATION_INIT);	
			                break;
			            case 8://Integer.valueOf("0008")
			            	baseController.addRegisterEventType(AppEvents.DESKTOP_APPLICATION_RENDER);	
			                break;
			            case 10://Integer.valueOf("0008")
			            	baseController.addRegisterEventType(AppEvents.DESKTOP_SUB_APPLICATION_INIT);	
			                break;
			                
			            case 101://Integer.valueOf("0101")
			            	baseController.addRegisterEventType(AppEvents.WINDOW_ININT);
			                break;
			            case 201://Integer.valueOf("0201")
			            	baseController.addRegisterEventType(AppEvents.CONTENTPANEL_ININT);
			                break;
			            case 301://Integer.valueOf("0301")
			            	baseController.addRegisterEventType(AppEvents.FORM_TEXTFIELD_ONCLICK);
			                break;
			            case 401://Integer.valueOf("0401")
			            	baseController.addRegisterEventType(AppEvents.LOAD_DATA_EVENT);
			                break;
			            case 601://Integer.valueOf("0401")
			            	baseController.addRegisterEventType(AppEvents.GRID_RELOAD);
			                break;
			            case 602://Integer.valueOf("0401")
			            	baseController.addRegisterEventType(AppEvents.GRID_RELOAD_COLUMN);
			                break;
			            case 603://Integer.valueOf("0401")
			            	baseController.addRegisterEventType(AppEvents.GRID_RELOAD_STORE);
			                break;
			            default:
			                break;
			        }
				}

	
			 */
			/*if (appEventCodes==null) {
				appEventCodes = new HashSet<GxtAppEventType>();
			}*/
			
		
		}
	}

}
